package com.qianyu.project.mapper.provider.smj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;

import java.util.Map;

public class smjApplyProvider {
    public String listApply(Map<String, String> params, IPage<Map<String, Object>> page){
        return new SQL(){
            {
                SELECT("app.*,lc.contract_name,lc.advance_pay,pi.project_name ,pi2.provider_name");
                FROM("apply_progress_payment app");
                LEFT_OUTER_JOIN("labor_contract lc on app.ctr_id=lc.id");
                LEFT_OUTER_JOIN("project_info pi on app.p_id=pi.id");
                LEFT_OUTER_JOIN("provider_info pi2 on app.company_id = pi2.id");
                if (!ObjectUtils.isEmpty(params.get("id"))){
                    WHERE("app.id = '"+params.get("id")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("agree_amount"))){
                    WHERE("app.agree_amount >= '"+params.get("agree_amount")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("agree_amount2"))){
                WHERE("app.id <= '"+params.get("agree_amount2")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("payment_name"))){
                    WHERE("app.payment_name = '"+params.get("payment_name")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("contract_signatory"))){
                    WHERE("app.handler_id = '"+params.get("contract_signatory")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("start_date"))){
                    WHERE("app.apply_date >= '"+params.get("start_date")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("end_date"))){
                    WHERE("app.apply_date <= '"+params.get("end_date")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("projectId"))){
                    WHERE("app.p_id = '"+params.get("projectId")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("providerId"))){
                    WHERE("app.company_id = '"+params.get("providerId")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("laberId"))){
                    WHERE("app.ctr_id = '"+params.get("laberId")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("approve_status"))){
                    WHERE("app.approve_status = '"+params.get("approve_status")+"'");
                }
            }
        }.toString();
    }
}
